import pymysql

class MyDB():
    def __init__(self):
        self.con = pymysql.connect(
            user="root",
            password="Admin@888",
            host='192.168.1.9',
            database="brtc_api",
            port = 3306,
            autocommit = True
        )
        # 创建游标
        self.cursor = self.con.cursor()

    # 查询一条数据
    def get_one(self, sql):
        # 执行sql
        self.cursor.execute(sql)
        # 返回一条数据
        return self.cursor.fetchone()
    # 释放数据库连接

    # 执行DML语言
    def execute_sql(self,sql):
        self.cursor.execute(sql)
        self.con.commit()

    def __del__(self):
        self.cursor.close()
        self.con.close()

# 实例化MyDB()
mydb = MyDB()